package com.company.iterator;

/**
 * 具体迭代器角色，车库迭代器
 */
public class CarGarageIterator implements Iterator {

    private CarGarageAggregate carGarage;
    private int index;

    public CarGarageIterator(CarGarageAggregate carGarage) {
        this.carGarage = carGarage;
        this.index = 0;
    }

    public boolean hasNext() {
        if (index < carGarage.length()) {
            return true;
        } else {
            return false;
        }
    }

    public Object next() {
        Car car = carGarage.get(index);
        index++;
        return car;
    }
}
